import time
NOT_REACHED = False
aCapo = bytes("\r\n",encoding="UTF-8")

class UnsupportedProtocol(Exception):
    pass
class Assertion1Error(Exception):
    pass

class DatiAvanzatiCondition(Exception):
    pass

def assert1(statement):
    if not statement:
        raise Assertion1Error

def alnum_and_chars(string, chars=[]):
    count = 0
    while count < len(string):
        if not string[count].isalnum() and string[count] not in chars:
            string = string[0:count-1] + string[count:]
            count -= 1
        count += 1
    return string

wday = ['mon','tue','wed','thu','fri','sat','sun']
mon = ['None','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
def dateRFC1123(time_struct):
    wd = wday[time_struct.tm_wday]
    m = mon[time_struct.tm_mon]
    return time.strftime(wd +", %d "+m+" %Y %H:%M:%S %Z",time_struct)

def readRFC1123(string):
    #buttiamo via il giorno
    try:
        parti = string.split(",")[1].split()
        #print(parti)
    except:
        raise
    gmese = parti[0]
    nmese = str(mon.index(parti[1].lower()))
    return time.strptime("%s %s %s %s %s" % (gmese,nmese,parti[2],parti[3],parti[4]), "%d %m %Y %H:%M:%S %Z")
    
#print(dateRFC1123(time.gmtime()))

class FakeMessage:
    def __init__(self,conn,payload):
        self.destinatario = conn
        self.payload = payload
